import 'package:tiktokadult/hj_model/like_record_model.dart';
import 'package:tiktokadult/hj_model/list_base_model.dart';
import 'package:tiktokadult/hj_model/mine/ExchangeRecordModel.dart';
import 'package:tiktokadult/hj_model/user/mobile_login_model.dart';
import 'package:tiktokadult/hj_model/user/user_income_info_model.dart';
import 'package:tiktokadult/hj_model/user/user_info_model.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_page/main_page/provider/msg_provider.dart';
import 'package:tiktokadult/hj_page/mine_business/mine_vip/coupon_model.dart';
import 'package:tiktokadult/hj_page/user_center_page/switch_background_entity.dart';
import 'package:tiktokadult/hj_utils/http_manager.dart';
import 'package:tiktokadult/tools_base/event_bus/event_bus_util.dart';
import 'package:tiktokadult/tools_base/event_bus/events.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';
import 'package:tiktokadult/tools_base/net/base_resp_bean.dart';

import '../../hj_model/cartoon_media_info.dart';
import '../../hj_model/countdown_update_model.dart';
import '../../hj_model/message/message_bean.dart';
import '../../hj_model/message/message_dynamic_list.dart';
import '../../hj_model/message/message_unread_list.dart';
import '../../hj_model/mine/OfficialListItemModel.dart';
import '../../hj_model/mine/base_list_res.dart';
import '../../hj_model/mine/credit_record_model.dart';
import '../../hj_model/mine/excharge/bill_page_model.dart';
import '../../hj_model/mine/excharge/recharge_list_model.dart';
import '../../hj_model/mine/excharge/recharge_url_model.dart';
import '../../hj_model/mine/promotion_record.dart';
import '../../hj_model/mine/task_center_data.dart';
import '../../hj_model/user/mine_video.dart';
import '../../hj_model/user/wallet_model_entity.dart';
import '../../hj_page/mine_business/make_money/in_come_entity.dart';
import '../../hj_page/mine_business/make_money/withdraw_details_model.dart';
import '../../hj_page/mine_business/message/UnReadMsgNumModel.dart';
import '../../hj_page/mine_business/mine_profit/mine_profit_page/model/alipay_bank_list_model.dart';
import '../../hj_page/mine_business/mine_vip/vip_support_model.dart';

class MineService {
  /// 设备和二维码登陆
  /// [devID] 设备id
  /// [qrCnt] qr二维码
  /// [devType] 设备信息
  /// [sysType] ios/android
  /// [ver] version
  /// [buildID] packageName
  /// [devToken] 登录设备id验签
  /// [cutInfos] 粘贴板信息

  static Future<UserInfoModel?> devLogin(
    devID,
    qrCnt,
    devType,
    sysType,
    ver,
    buildID,
    devToken, [
    cutInfos = "",
  ]) async {
    ArgumentError.checkNotNull(devID, 'devID');
    ArgumentError.checkNotNull(qrCnt, 'qrCnt');
    ArgumentError.checkNotNull(devType, 'devType');
    ArgumentError.checkNotNull(sysType, 'sysType');
    ArgumentError.checkNotNull(ver, 'ver');
    ArgumentError.checkNotNull(buildID, 'buildID');
    ArgumentError.checkNotNull(devToken, 'devToken');
    final param = {
      'devID': devID,
      'qrCnt': qrCnt,
      'devType': devType,
      'sysType': sysType,
      'ver': ver,
      'buildID': buildID,
      'devToken': devToken,
      'cutInfos': cutInfos
    };
    param.removeWhere((k, v) => v == null);

    final result = await httpManager.fetchResponseByPOST(
      '/mine/login',
      param: param,
      jsonTransformation: (json) => UserInfoModel.fromJson(json),
    );
    if (result.isSuccess) return result.data;
    return null;
  }

  static Future<bool> reduceDownloadCount() async {
    return (await httpManager.fetchResponseByPOST('/mine/download/use', param: <String, dynamic>{})).isSuccess;
  }

  /// 获取用户信息
  /// uid == 0 查询自己否则查询别人
  static Future<UserInfoModel?> getUserInfo([uid = 0]) async {
    final param = {'uid': uid};
    final result = await httpManager.fetchResponseByGET(
      '/mine/info',
      param: param,
      jsonTransformation: (json) => UserInfoModel.fromJson(json),
    );
    return result.data;
  }

  /// 提现明细
  static Future<WithdrawDetailsModel?> getWithdrawDetails({int pageNumber = 1, int pageSize = 10}) async {
    final result = await httpManager.fetchResponseByGET(
      '/withdraw/order',
      param: {
        'pageNumber': pageNumber,
        'pageSize': pageSize,
      },
      jsonTransformation: (json) => WithdrawDetailsModel.fromJson(json),
    );
    return result.data;
  }

  /// 提现配置
  static Future<WithdrawConfig?> withdrawConfig() async {
    final result = await httpManager.fetchResponseByGET(
      '/withdraw/cfg',
      jsonTransformation: (json) => WithdrawConfig.fromJson(json),
    );

    //MinePublishDetailsModel
    return result.data;
  }

  /// 头像
  static Future<UserBgAvatarRep?> getBloggerAvatarAndBg(
    String type, {
    int page = 1,
    int size = 20,
  }) async {
    final queryParameters = <String, dynamic>{
      'type': type,
      'pageNumber': page,
      'pageSize': size,
    };
    final result = await httpManager.fetchResponseByGET(
      '/mine/userresource/list',
      param: queryParameters,
      jsonTransformation: (json) => UserBgAvatarRep.fromJson(json),
    );
    return result.data;
  }

  /// 提现
  static Future<bool> withdraw(
    String? payType,
    String? act,
    int? money,
    String? name,
    String? actName,
    String? devID,
    String? bankCode,
    int? withdrawType,
    int? productType,
  ) async {
    final _data = {
      'payType': payType,
      'act': act,
      'money': money,
      'name': name,
      'actName': actName,
      'devID': devID,
      'bankCode': bankCode,
      'withdrawType': withdrawType,
      'productType': productType,
    };
    _data.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/withdraw',
      param: _data,
    );
    return result.isSuccess;
  }

  static Future<bool> updateUserInfo(Map<String, dynamic>? map) async {
    final param = <String, dynamic>{};
    param.addAll(map ?? {});
    final result = await httpManager.fetchResponseByPOST(
      '/mine/info',
      param: param,
    );
    return result.isSuccess;
  }

  static Future<MobileLoginModel?> mobileLogin(
      String? mobile, String? code, String? devID, String? devType, String? sysType, String? ver, String? buildID,
      [String? cutInfos = ""]) async {
    final param = {
      'mobile': mobile,
      'code': code,
      'devID': devID,
      'devType': devType,
      'sysType': sysType,
      'ver': ver,
      'buildID': buildID,
      'cutInfos': cutInfos
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST('/mine/mobileLoginOnly',
        param: param, jsonTransformation: (json) => MobileLoginModel.fromJson(json));
    return result.data;
  }

  /// 获取客服对接地址
  static Future<String> fetchCustomService() async {
    final result = await httpManager.fetchResponseByGET('/im/whiteSign', param: {});
    return result.data;
  }

  /// 积分兑换商品
  static Future<bool> integralExchangeSomething(String id, {String? name, String? tel, String? address}) async {
    final param = <String, dynamic>{"id": id, "name": name, "tel": tel, "address": address};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByPOST('/integral/exchangeIntegral', param: param);
    return result.isSuccess;
  }

  //收藏类型 SP:长视频 SHORT:短视频 COVER:图文帖子 PIC:图集帖子 SEED_LINK:种子/黄油帖子
  static Future<bool> postCollect(String? objID, String? type, bool? isCollect) async {
    final param = {'objID': objID, 'type': type, 'isCollect': isCollect};
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/mine/collect',
      param: param,
    );
    eventBus.emit(CollectStatusModel(id: objID, isCollected: isCollect, type: type));
    return result.isSuccess;
  }

  static Future<bool> postUpThumbDown(
    String? objID,
    String? type,
  ) async {
    final param = {
      'objID': objID,
      'type': type,
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/thumbsDown',
      param: param,
    );
    eventBus.emit(CollectStatusModel(id: objID, isCollected: false, type: type));
    return result.isSuccess;
  }

  static Future<WalletModelEntity> fetchWalletData() async {
    final result =
        await httpManager.fetchResponseByGET('/mine/wallet', param: {}, jsonTransformation: (json) => WalletModelEntity.fromJson(json));
    if (result.data is WalletModelEntity) {
      globalStore.wallet = result.data;
    }
    return result.data;
  }

  ///购买视频 productType： 19 购买整本，25 购买子集
  static Future<BaseRespBean> postBuyVideo(
    String? productID,
    int? productType, {
    String? couponId, // 优惠卷ID
    int? goldVideoCouponNum, //金币视频抵用券金币面值,
    String? serviceId, // 裸聊服务ID
  }) async {
    final param = <String, dynamic>{
      'productID': productID,
      'productType': productType,
      'couponId': couponId,
      'goldVideoCouponNum': goldVideoCouponNum,
      'serviceId': serviceId,
      'isH5': false,
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/product/buy',
      param: param,
    );
    return result;
  }

  //关注
  static Future<bool> getFollow(dynamic followUID, bool isFollow) async {
    final param = {'followUID': followUID, 'isFollow': isFollow};
    final result = await httpManager.fetchResponseByPOST(
      '/mine/follow',
      param: param,
    );
    eventBus.emit(CollectStatusModel(uid: followUID, isFollowed: isFollow));
    return result.isSuccess;
  }

  //推广记录

  static Future<ListBaseModel<Promotion>?> getProxyBindRecord(int? pageSize, int? pageNumber) async {
    final param = {'pageSize': pageSize, 'pageNumber': pageNumber};
    final result = await httpManager.fetchResponseByPOST(
      '/userinvite/userlist',
      param: param,
      jsonTransformation: (json) => ListBaseModel<Promotion>.fromJson(json),
    );
    return result.data;
  }

  //playTimeType: 0 默认全部 1 视频 2 帖子
  //type: hot 热度值排序；watch 最多播放；like 最多点赞(收藏)；new 最新视频
  //status: 0 审核中  1 已通过 2未通过
  // newsType: SEED_LINK 游戏， MOVIE 视频，抖音：SP，图文：COVER

  static Future<MineCollect<VideoModel>> fetchMyCollection({
    int page = 1,
    int size = 10,
    int? playTimeType,
    String? type,
    int? uid,
    int? verifyStatus,
    String? newsType,
    String? status,
  }) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'newsType': newsType,
      'type': type,
      'uid': uid,
      'sortType': verifyStatus,
      'status': status
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/mine/collection',
        param: param, jsonTransformation: (json) => MineCollect<VideoModel>.fromJson(json));
    return result.data;
  }

  static Future<UserIncomeModel?> fetchAllIncomeInfo() async {
    final param = <String, dynamic>{};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByPOST('/userinvite/info',
        param: param, jsonTransformation: (json) => UserIncomeModel.fromJson(json));
    return result.data;
  }

  /// 获取用户分享列表

  static Future<InviteIncomeModel?> fetchAllIncomeList({int page = 1, int size = 10}) async {
    final param = <String, dynamic>{'pageSize': page, 'pageNumber': size};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByPOST('/userinvite/incomelist',
        param: param, jsonTransformation: (json) => InviteIncomeModel.fromJson(json));
    return result.data;
  }

  static Future<MineCollect> fetchMyLike({
    int page = 1,
    int size = 10,
    String? likeType,
    int? uid,
  }) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'likeType': likeType,
      'uid': uid,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET(
      '/mine/like',
      param: param,
      jsonTransformation: (json) {
        if (likeType == 'image' || likeType == 'video' || likeType == 'text') {
          return MineCollect<CartoonMediaInfo>.fromJson(json);
        }
        return MineCollect<VideoModel>.fromJson(json);
      },
    );
    return result.data;
  }

  /// 获取我买过电影
  /// [page] 页码 默认1
  /// [size] 页大小 默认20
  /// [newsType] 购买类型 SP视频，COVER：图集，POST：帖
  /// [uid] 查询自己不传
  static Future<MineCollect?> fetchMineBuyVideo({
    int page = 1,
    int size = 20,
    int? uid,
    String? newsType,
  }) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'newsType': newsType,
      'uid': uid,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/mine/buyVid',
        param: param, jsonTransformation: (json) => MineCollect<VideoModel>.fromJson(json));
    return result.data;
  }

  /// 用户购买合集列表
  // static Future<MineCollect?> fetchMineBuyCollections(
  //   int userPayType, {
  //   int page = 1,
  //   int size = 20,
  // }) async {
  //   final param = <String, dynamic>{'pageNumber': page, 'pageSize': size, 'userPayType': userPayType};
  //   param.removeWhere((key, value) => value == null);
  //   final result = await httpManager.fetchResponseByGET('/mine/buyCollection',
  //       param: param, jsonTransformation: (json) => MineCollect<CollectionModel>.fromJson(json));
  //   return result.data;
  // }

  static Future<MineCollect?> fetchMineBuyMedia({
    int page = 1,
    int size = 20,
    String? mediaType,
  }) async {
    final param = <String, dynamic>{
      'pageNumber': page,
      'pageSize': size,
      'mediaType': mediaType,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/mine/buyAcg',
        param: param, jsonTransformation: (json) => MineCollect<CartoonMediaInfo>.fromJson(json));
    return result.data;
  }

  // 账单类型0_全部 1_金币 2_积分
  static Future<BillPageModel?> getBillData({
    required int pageNumber,
    required int pageSize,
    int? type,
  }) async {
    final param = {
      'pageNumber': pageNumber,
      'pageSize': pageSize,
      'type': type,
      'year': DateTime.now().year,
      'month': DateTime.now().month
    };
    param.removeWhere((k, v) => v == null);
    final result =
        await httpManager.fetchResponseByGET('/mine/zhangdan', param: param, jsonTransformation: (json) => BillPageModel.fromJson(json));
    return result.data;
  }

  // 充值记录
  static Future<WithdrawDetailsModel?> getRechargeBill({
    required int pageNumber,
    required int pageSize,
  }) async {
    final param = {
      'pageNumber': pageNumber,
      'pageSize': pageSize,
    };
    final result = await httpManager.fetchResponseByPOST('/mine/transaction',
        param: param, jsonTransformation: (json) => WithdrawDetailsModel.fromJson(json));
    return result.data;
  }

  // 收益明细
  static Future<IncomeModelList?> getIncomeRecord({
    required int pageNumber,
    required int pageSize,
  }) async {
    final param = {
      'pageNumber': pageNumber,
      'pageSize': pageSize,
    };
    final result = await httpManager.fetchResponseByGET(
      '/mine/iIncomes',
      param: param,
      jsonTransformation: (json) => IncomeModelList.fromJson(json),
    );
    return result.data;
  }

  //收藏的影视 video / img
  static Future<MineCollect<T>?> fetchMineCollectList<T>(
    String type, {
    int page = 1,
    int size = 20,
    int? uid,
  }) async {
    final param = {
      "type": type,
      'pageNumber': page,
      'pageSize': size,
      'uid': uid ?? globalStore.meInfo?.uid,
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByGET(
      '/mine/collect/infoList',
      param: param,
      jsonTransformation: (json) => MineCollect<T>.fromJson(json),
    );
    return result.data;
  }

  ///获取充值金额列表
  static Future<RechargeListModel?> getNakeChatRechargeTypeList(int? type) async {
    final param = {'type': type};
    final result = await httpManager.fetchResponseByGET('/mine/currencys',
        param: param, jsonTransformation: (json) => RechargeListModel.fromJson(json));
    return result.data;
  }

  /// 金币充值
  ///[finalPayStatus]: 预售业务，true 付尾款， false 付预定款；null 非预售业务；
  ///[goldExtraID] 金币加赠券只有充值金币用到
  /// [rechargeType] 支付渠道
  ///
  static Future<RechargeUrlModel?> chargeGoldCoin(String? rechargeType,
      {String? productId, bool? isVip, String? goldExtraID, bool? finalPayStatus}) async {
    ArgumentError.checkNotNull(rechargeType, 'rechargeType');
    final param = {
      'rechargeType': rechargeType,
      'productId': productId,
      'buyType': isVip == true ? 4 : 1,
      'cId': goldExtraID?.isNotEmpty == true ? goldExtraID : null,
      'uid': globalStore.getMe()?.uid,
      'goldExtraID': goldExtraID,
      'finalPayStatus': finalPayStatus
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/mine/topay',
      param: param,
      jsonTransformation: (json) => RechargeUrlModel.fromJson(json),
    );
    return result.data;
  }

  ///意见反馈
  static Future<bool> feedback(
    String content, {
    String? location,
    String? device,
    String? carrier,
    String? contact,
    List<String>? img,
    String? fType,
  }) async {
    final param = {
      'desc': content,
      "region": location,
      "devInfo": device,
      "ISP": carrier,
      'images': img,
      'cateInfo': fType,
      'contact': contact
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/mine/feedback',
      param: param,
    );
    return result.isSuccess;
  }

  ///查询推广码
  static Future<String> querySpreadCode() async {
    final result = await httpManager.fetchResponseByPOST(
      '/mine/inviter',
      param: {},
    );
    String value = '';
    if (result.isSuccess) {
      value = result.data["inviter"]?.toString() ?? '';
    }
    return value;
  }

  //vip倒计时
  static Future<Countdown?> getCutDown() async {
    final result = await httpManager.fetchResponseByGET(
      '/vip/tiroCountdown',
      param: {},
      jsonTransformation: (json) => Countdown.fromJson(json),
    );
    return result.data;
  }

  //积分兑换记录
  static Future<List<CreditRecordModel>> getCreditRecords({int pageNumber = 1, int pageSize = 20}) async {
    final param = {'pageNumber': pageNumber, 'pageSize': pageSize};
    final result = await httpManager.fetchResponseByGET(
      '/integral/record/list',
      param: param,
    );
    final List<CreditRecordModel> list = [];
    if (result.isSuccess) {
      List? values = result.data as List?;
      list.addAll(values?.map((e) => CreditRecordModel.fromJson(e)).toList() ?? []);
    }
    return list;
  }

  ///获取所有会员卡信息列表
  static Future<VipSupportModel?> getVipProductInfo({int? status}) async {
    final param = <String, dynamic>{'status': status};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET(
      '/vip/product',
      param: param,
      jsonTransformation: (json) => VipSupportModel.fromJson(json),
    );
    return result.data;
  }

  //积分兑换列表
  static Future<List<IntegralExchangeModel>> fetchIntegralExchangeList() async {
    final result = await httpManager.fetchResponseByGET(
      '/integral/list',
      param: {},
    );
    final List<IntegralExchangeModel> list = [];
    if (result.isSuccess) {
      List? values = result.data as List?;
      list.addAll(values?.map((e) => IntegralExchangeModel.fromJson(e)).toList() ?? []);
    }
    return list;
  }

  //获取官方社群
  static Future<List<OfficialListItemModel>?> getOfficialLists() async {
    final param = {
      'type': 2,
    };
    final result = await httpManager.fetchResponseByGET(
      '/official/list',
      param: param,
    );
    final List<OfficialListItemModel> list = [];
    if (result.isSuccess) {
      List? values = result.data as List?;
      list.addAll(values?.map((e) => OfficialListItemModel.fromJson(e)).toList() ?? []);
    }
    return list;
  }

  //领取积分
  static Future<bool> receiveIntegral(String? taskId, int? type) async {
    final param = {'taskId': taskId, 'type': type};
    final result = await httpManager.fetchResponseByPOST(
      '/task/receive',
      param: param,
    );
    return result.isSuccess;
  }

  //
  //娱乐模块点击统计事件接口
  // id  点击id
  // type  广告类型. app 或 adv
  // sysType  设备类型. android或ios
  static Future<bool> recreationList(String id, String type) async {
    final param = {
      "id": id,
      "type": type,
      "sysType": "android",
    };
    final result = await httpManager.fetchResponseByPOST(
      '/recreation/click',
      param: param,
      // jsonTransformation: (json) => HappyModel.fromJson(json),
    );
    return result.isSuccess;
  }

  //任务列表
  static Future<TaskCenterData?> fetchTaskInfo() async {
    final result = await httpManager.fetchResponseByGET(
      '/task',
      param: {},
      jsonTransformation: (json) => TaskCenterData.fromJson(json),
    );
    if (result.isSuccess) {
      return result.data;
    }
    return null;
  }

  ///金币购买vip
  ///[finalPayStatus]: 预售业务，true 付尾款， false 付预定款；null 非预售业务；
  ///[couponId] 金币加赠券券id
  static Future buyVipProduct(int? productType, String? productID, String? productName, int? discountedPrice,
      {String? couponId = "", bool? finalPayStatus, int? diffPrice}) async {
    final param = {
      'productType': productType,
      'productID': productID,
      'productName': productName,
      'discountedPrice': discountedPrice,
      'couponId': couponId,
      'finalPayStatus': finalPayStatus,
      'diffPrice': diffPrice
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/product/buy',
      param: param,
    );
    return result.data;
  }

  //兑换码兑换
  static Future<bool> postExchangeCode(String code) async {
    final param = {'code': code};
    final result = await httpManager.fetchResponseByPOST(
      '/code/exchange',
      param: param,
    );
    return result.isSuccess;
  }

  //绑定邀请码
  static Future<bool> getProxyBind(String promotionCode) async {
    final param = {'promotionCode': promotionCode};
    final result = await httpManager.fetchResponseByPOST(
      '/proxy/bind',
      param: param,
    );
    return result.isSuccess;
  }

  //发送验证码 type, 1绑定手机号，2 找回账号;
  static Future<bool> postCaptchaCode(String phone, int type) async {
    final param = {
      'type': type,
      'mobile': "+86$phone",
    };
    final result = await httpManager.fetchResponseByPOST(
      '/notification/captcha',
      param: param,
    );
    return result.isSuccess;
  }

  //绑定手机
  static Future<bool> bindPhone(String phone, String code,
      {String? devID, String? smsId, String? sysType, String? ver, String? devType, String? applicationID}) async {
    final param = {
      'mobile': "+86$phone",
      'code': code,
      'devID': devID,
      'smsId': smsId,
      'sysType': sysType,
      'ver': ver,
      'devType': devType,
      'applicationID': applicationID
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByPOST(
      '/mine/mobileBind',
      param: param,
    );
    return result.isSuccess;
  }

  //获取sessionId
  static Future<String?> getSessionId({required int uid}) async {
    final param = {'takeUid': uid};
    final result = await httpManager.fetchResponseByGET(
      '/msg/session/get',
      param: param,
    );
    return result.data != null ? result.data.toString() : null;
  }

  //动态、收益列表
  static Future<MessageDynamicModel?> getDynamicList({int pageNumber = 1, int pageSize = 20, int? msgType}) async {
    final param = {
      'pageNumber': pageNumber,
      'pageSize': pageSize,
      'msgType': msgType,
    };
    param.removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByGET('/msg/dynamic/list',
        param: param, jsonTransformation: (json) => MessageDynamicModel.fromJson(json));
    if (result.isSuccess) {
      return result.data;
    }
    return null;
  }

  //私信列表
  static Future<BaseListResEntity<MessageUnreadList>?> getUnReadChat({int pageNumber = 1, int pageSize = 20}) async {
    final param = {'pageNumber': pageNumber, 'pageSize': pageSize};
    final result = await httpManager.fetchResponseByGET(
      '/msg/session/list',
      param: param,
    );
    if (result.isSuccess) {
      BaseListResEntity<MessageUnreadList> value = BaseListResEntity.fromJson(result.data, (v) => MessageUnreadList.fromJson(v));
      return value;
    }
    return null;
  }

  //未读消息列表
  static Future<UnReadMsgNumModel?> getUnReadNum() async {
    final result = await httpManager.fetchResponseByGET(
      '/msg/dynamic/noRedNum',
      param: {},
      jsonTransformation: (json) => UnReadMsgNumModel.fromJson(json),
    );
    return result.isSuccess ? result.data : null;
  }

  //会话消息列表
  static Future<BaseListResEntity<MessageBean>?> getChatMessage({int pageNumber = 1, int pageSize = 20, required String sessionId}) async {
    final param = {'pageNumber': pageNumber, 'pageSize': pageSize, 'sessionId': sessionId};
    final result = await httpManager.fetchResponseByGET(
      '/msg/message/list',
      param: param,
    );
    if (result.isSuccess) {
      BaseListResEntity<MessageBean> value = BaseListResEntity.fromJson(result.data, (v) => MessageBean.fromJson(v));
      return value;
    }
    return null;
  }

  /// 黑料社获取用户优惠券
  static Future<List<CouponModel>> fetchUserCouponByType(int type, {int page = 1, int size = 0}) async {
    final param = <String, dynamic>{
      'type': type,
      'pageNumber': page,
      'pageSize': size,
    };
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/coupon/list',
        param: param, jsonTransformation: (json) => (json['list'] as List?)?.map((e) => CouponModel.fromJson(e)).toList() ?? []);
    return result.data;
  }

  static Future<bool> bankCardDelete({String? id}) async {
    final param = <String, dynamic>{'id': id};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByDELETE(
      '/mine/txnact/del',
      param: param,
    );
    return result.isSuccess;
  }

  static Future<ApBankListModel?> getBankCardList() async {
    final param = <String, dynamic>{};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/mine/txnact/yh/get',
        param: param, jsonTransformation: (json) => ApBankListModel.fromJson(json));
    return result.data;
  }

  static Future<bool> getAddBankCard(
    String? act,
    String? actName,
    String? bankCode,
    String? cardType,
  ) async {
    final param = <String, dynamic>{'act': act, 'actName': actName, 'bankCode': bankCode, 'cardType': cardType};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByPOST(
      '/mine/txnact/yh/add',
      param: param,
    );
    return result.isSuccess;
  }

  //获取兑换码记录
  static Future<ExchangeRecordModelList?> getExchangeRecord(int pageNumber, int pageSize) async {
    final result = await httpManager.fetchResponseByGET(
      '/code/userRecord',
      param: {
        'pageNumber': pageNumber,
        'pageSize': pageSize,
      },
      jsonTransformation: (json) => ExchangeRecordModelList.fromJson(json),
    );
    return result.data;
  }

  //获取消息小红点
  static Future<NewMessageTip?> checkMessageTip() async {
    final result = await httpManager.fetchResponseByGET(
      '/ping/checkMessageTip',
      param: {},
      jsonTransformation: (json) => NewMessageTip.fromJson(json),
    );
    return result.data;
  }

  //获取消息小红点
  static Future<String?> certificateQR() async {
    final result = await httpManager.fetchResponseByGET(
      '/mine/certificate/qr',
      param: {},
      jsonTransformation: (json) {
        return json['content'] ?? '';
      },
    );
    return result.data;
  }

  static Future<List<String>> getPortrait() async {
    final result = await httpManager.fetchResponseByGET(
      '/mine/portrait',
    );
    final List<String> list = [];
    if (result.isSuccess) {
      List? values = result.data['data'] as List?;
      list.addAll(values?.map((e) => e as String).toList() ?? []);
    }
    return list;
  }

  //绑定邀请码
  static Future<bool> postExchangeInviteCode(String code) async {
    final param = {'promotionCode': code};
    final result = await httpManager.fetchResponseByPOST(
      '/mine/inviteBind',
      param: param,
    );
    return result.isSuccess;
  }

  //type: hot 热度值排序；watch 最多播放；like 最多点赞(收藏)；new 最新视频
  //status: 0 审核中  1 已通过 2未通过

  static Future<MineCollect<VideoModel>> fetchMyPublishes({
    int page = 1,
    int size = 10,
    int status = 0,
    String? newsType,
    int? uid,
  }) async {
    final param = <String, dynamic>{'pageNumber': page, 'pageSize': size, 'status': status, 'uid': uid, 'newsType': newsType};
    param.removeWhere((key, value) => value == null);
    final result = await httpManager.fetchResponseByGET('/mine/publish',
        param: param, jsonTransformation: (json) => MineCollect<VideoModel>.fromJson(json));
    return result.data;
  }

  static Future<String> deleteMyPublishes({
    List<String>? ids,
  }) async {
    final param = <String, dynamic>{'ids': ids};
    final result = await httpManager.fetchResponseByPOST('/mine/publish/delete', param: param);
    if (result.isSuccess) {
      return '';
    }
    return result.tip ?? result.msg ?? '';
  }

  //获取优惠券
  static Future<List<AICouponModel>?> backPack(
    int page, {
    int? limit = 10, //每页条数
    int? status = 2, //物品状态 1-已使用 2-未使用 3-过期
    int? type = 3, //1-楼风解锁折扣卷 2-会员折扣卷 3-AI换脸折扣券
  }) async {
    final param = <String, dynamic>{
      'page': page,
      'limit': limit,
      'status': status,
      'type': type,
    }..removeWhere((k, v) => v == null);
    final result = await httpManager.fetchResponseByGET(
      '/backpack',
      param: param,
      jsonTransformation: (json) => CouponModel.fromJson(json),
    );
    final List<AICouponModel> list = [];
    if (result.isSuccess) {
      List? values = result.data as List?;
      list.addAll(values?.map((e) => AICouponModel.fromJson(e)).toList() ?? []);
    }
    return list;
  }

  //被点赞列表
  static Future<LikeRecordListResp?> getLikeRecordList({int pageNumber = 1, int pageSize = 20}) async {
    final param = {'pageNumber': pageNumber, 'pageSize': pageSize};
    final result = await httpManager.fetchResponseByGET('/api/app/like/record/list',
        param: param, jsonTransformation: (json) => LikeRecordListResp.fromJson(json));
    return result.data;
  }
}
